
import React from "react";

//受控组件
export default class ChooseLogin extends React.Component {
	state = {
       username:'',
       password:''
    }
	render() {

		return (
			<div style={{marginTop:'10px'}}>
				<form onSubmit={this.handlerSubmit}>
                    用户名<input onChange={this.saveFormData("username")}/>
                    密码<input  onChange={this.saveFormData("password")}/>
                    <button>登录</button> 
                </form>
			</div>
		)
	}
    saveFormData = (dataType)=>{
        return (event)=>{
            this.setState({[dataType]:event.target.value})
        }
    }
    saveUsername = (event)=>{
        // console.log('saveUsername',event.target.value)
        // this.setState({username:event.target.value})
    }
    savePassword = (event)=>{
        // console.log('savePassword',event.target.value)
        // this.setState({password:event.target.value})
    }
    handlerSubmit = (event)=>{
        event.preventDefault()
        const {username,password} = this.state
        alert(`用户名：${username},密码：${password}`)
    }
}